import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/bottom_enter_page.dart';
import 'package:app/pages/office_supplies_modules/crate_office_module/create_office_controller.dart';
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';

import '../../../common/app_theme.dart';
import '../../../common/colors.dart';
import '../../../utils/hexcolor.dart';

class CreateOfficeView extends GetView{

  CreateOfficeController controller = Get.put(CreateOfficeController());

  bool submit = false;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: BaseAppBar(
        preferredSize: Size(Get.width, AppTool.appBarHEIGHT),
        child: Text('新建'),
      ),
      body: GetBuilder<CreateOfficeController>(builder: (_){
        return Column(
          children: [
            Expanded(child: ListView(
              children: [
                GestureDetector(
                    onTap: () async {
                      controller.tapClickUser();
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                      color: HexColor('#FEFEFE'),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("使用人",style: TextStyle(fontSize: 17),),
                          Container(
                              height: 40,
                              child: Row(
                                mainAxisAlignment:
                                MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text(controller.userIdName[0]),
                                  const Icon(
                                    Icons.arrow_forward_ios,
                                    size: 15,
                                  )
                                ],
                              )),
                        ],
                      ),
                    )),
                submit==false?SizedBox():controller.userId==null?buildFieldError('请选择使用人'):SizedBox(),
                GestureDetector(
                    onTap: () async {
                      controller.taoClickGoods();
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                      color: HexColor('#FEFEFE'),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("申请的用品",style: TextStyle(fontSize: 17),),
                          Container(
                              height: 40,
                              child: Row(
                                mainAxisAlignment:
                                MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text(controller.goodsName),
                                  const Icon(
                                    Icons.arrow_forward_ios,
                                    size: 15,
                                  )
                                ],
                              )),
                        ],
                      ),
                    )),
                submit==false?SizedBox():controller.goodsId==null?buildFieldError('请选择申请的用品'):SizedBox(),
                BrnStepInputFormItem(
                  title: "使用数量",
                  // subTitle: "这里是副标题",
                  value: 1,
                  maxLimit: 100,
                  minLimit: 1,
                  onTip: () {

                  },
                  onAddTap: () {

                  },
                  onRemoveTap: () {

                  },
                  onChanged: (oldValue, newValue) {
                    controller.number = newValue;
                    controller.update();
                  },
                ),
                GestureDetector(
                    onTap: () async {
                      controller.tapClickStartTime();
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(20, 10, 15, 10),
                      color: Colors.white,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("开始时间",style: TextStyle(fontSize: 17),),
                          // SizedBox(height: 12,),
                          Container(
                              height: 40,
                              child: Row(
                                mainAxisAlignment:
                                MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text('${controller.startTime}',style: appThemeData.textTheme.subtitle1,),
                                  Icon(
                                    Icons.arrow_forward_ios,
                                    size: 15,
                                    color: AppColor.smallTextColor,
                                  )
                                ],
                              )),
                        ],
                      ),
                    )),
                submit==false?SizedBox():controller.startTime=='请选择开始时间'?buildFieldError('请选择开始时间'):SizedBox(),

                GestureDetector(
                    onTap: () async {
                    },
                    child: Container(
                      padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                      color: HexColor('#FEFEFE'),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("使用区域",style: TextStyle(fontSize: 17),),
                          Container(
                            height: 40,
                            width: 100,
                            child: TextField(
                              controller: controller.placeKeepController,
                              textDirection: TextDirection.rtl,
                              decoration: InputDecoration(
                                  border: InputBorder.none,
                                  hintTextDirection: TextDirection.rtl,
                                  hintText: '使用区域'
                              ),
                            ),
                          ),
                        ],
                      ),
                    )),


              ],
            ),),
           Container(
             color: Colors.white,
             child:  BottomEnterPage((){

               submit = true;

               if(controller.userId!=null&&controller.goodsId!=null){
                 controller.requestDataWithCreate();
               }

               controller.update();
             }),
           )

          ],
        );
      }),
    );
  }
  Widget buildFieldError(errorType) {
    return Padding(padding: EdgeInsets.only(left: 15),child: Row(
      children: [
        // if(errors.contains(errorType))
        Expanded(
          child: Text(
              '${errorType}',
              textAlign: TextAlign.left,
              style: TextStyle(
                  color: Colors.red,
                  fontSize: 12
              )
          ),
        ),
      ],
    ),);
  }

}